package geo

import (
	es7 "github.com/olivere/elastic/v7"
	"math"
)

// 返回单位为：米
func GetDistance(location1, location2 *es7.GeoPoint) float64 {
	radius := 6371000.0 //6378137.0
	rad := math.Pi / 180.0
	lat1 := location1.Lat * rad
	lng1 := location1.Lon * rad
	lat2 := location2.Lat * rad
	lng2 := location2.Lon * rad
	theta := lng2 - lng1
	dist := math.Acos(math.Sin(lat1)*math.Sin(lat2) + math.Cos(lat1)*math.Cos(lat2)*math.Cos(theta))
	return dist * radius // 1000
}

func StringToGeoPoint(location string) (*es7.GeoPoint, error) {
	return es7.GeoPointFromString(location)
}
